package com.tz.marlon.web.comment;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tz.marlon.bean.Comment;
import com.tz.marlon.bean.TzParams;
import com.tz.marlon.dao.comment.ICommentDao;

@Controller
@RequestMapping("/comment")
public class CommentController {
	
	@Autowired
	private ICommentDao commentDao;
	
	@ResponseBody
	@RequestMapping(value="/save",method=RequestMethod.POST)
	public Comment saveComment(Comment comment,HttpServletRequest request){
		Integer userId = (Integer) request.getSession().getAttribute("userId");
		Integer type = Integer.parseInt(request.getParameter("type"));
		comment.setStatus(1);
		comment.setType(type);
		comment.setUserId(userId);
		commentDao.save(comment);
		return comment;
	}
	
	@ResponseBody
	@RequestMapping(value="/find",method=RequestMethod.POST)
	public List<HashMap<String, Object>> findComment(TzParams params,HttpServletRequest request){
		Integer blogId = Integer.parseInt(request.getParameter("blogId"));
		Integer type = Integer.parseInt(request.getParameter("type"));
		params.setBlogId(blogId);
		params.setStatus(1);
		params.setType(type);
		List<HashMap<String, Object>> comments = commentDao.listMaps(params);
		return comments;
	}
}
